﻿using System.Linq;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class BulletGlobal
    {
        private static BulletConfig[] configs;

        static BulletGlobal()
        {
            BattleBulletConfig rConfig = null;
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                rConfig = UnityEditor.AssetDatabase.LoadAssetAtPath<BattleBulletConfig>("Assets/" + PathConstant.GetBulletConfigPath());
            }
            else
#endif
            {
                var rLoader = ResLoader.Create();
                rConfig = rLoader.LoadABAsset<BattleBulletConfig>(PathConstant.GetBulletConfigPath());
            }            
            var nLen = rConfig.bulletConfig.Length;
            configs = new BulletConfig[nLen];
            for (int i = 0; i < rConfig.bulletConfig.Length; i++)
            {
                configs[i] = rConfig.bulletConfig[i];
            }
        }

        public static BulletConfig GetConfig(int nIndex)
        {
            return configs?[nIndex];
        }

        public static int Count => configs?.Length ?? 0;
    }
}